package com.example.myshop.Dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.myshop.domain.UserDao;
import com.example.myshop.entity.User;
import com.example.myshop.vo.PriorityVO;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Date;
import java.util.List;

@SpringBootTest
@RunWith(SpringRunner.class)
public class userdaotest {
@Autowired
    private UserDao userDao;
/*
@Test
public void insert() {
    User user = new User();
    user.setUsername("root2");
    user.setPassword("123");
    Integer rows = userDao.insert(user);
    System.out.println(rows);
}
@Test
    public void findbyusername(){
    QueryWrapper qw=new QueryWrapper<>();
    qw.eq("username","root1");
    List<User>users = userDao.selectList(qw);
    System.out.println(users);

}
    @Test
    public void updatePasswordByYid() {
            QueryWrapper queryWrapper=new QueryWrapper<>();
            queryWrapper.eq("uid","1");
            User user=new User();
            user.setPassword("change");
            user.setModifiedUser("com");
            Date date=new Date();
            user.setModifiedTime(date);
            userDao.update(user,queryWrapper);

    }

    @Test
    public void findByUid() {
    QueryWrapper<User>queryWrapper=new QueryWrapper<>();
    queryWrapper.eq("uid",1);
        User user = userDao.selectOne(queryWrapper);
        if (user.getUserType().equals("1")) {
            System.err.println("管理员");
        }
        System.out.println(user);
    }

    @Test
    public void updateInfoByUid() {
        User user = new User();
        user.setPhone("15701651900");
        user.setEmail("1123868000@qq.com");
        user.setGender(1);
        QueryWrapper<User>queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("uid",15);
        userDao.update(user,queryWrapper);
    }

    @Test
    public void updateAvatarByUid() {
    User user=new User();
    user.setAvatar("/upload/avatar.png");
    user.setModifiedUser("ZHANGQIAN");
    user.setModifiedTime(new Date());
    QueryWrapper<User>queryWrapper=new QueryWrapper<>();
    queryWrapper.eq("uid",15);
    userDao.update(user,queryWrapper);
    }

    @Test
    public void checkAllUsers() {
    List<User>users=userDao.selectList(null);
        users.forEach(System.out::println);
    }

    @Test
    public void passByAdmin() {
    User user=new User();
    user.setIs_pass(1);
    user.setModifiedTime(new Date());
    user.setModifiedUser("root1");
    QueryWrapper<User>queryWrapper=new QueryWrapper<>();
    queryWrapper.eq("uid",15);
    userDao.update(user,queryWrapper);
    }
    @Test
    public void rejectByAdmin() {
        User user=new User();
        user.setIs_pass(0);
        user.setModifiedTime(new Date());
        user.setModifiedUser("root1");
        QueryWrapper<User>queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("uid",15);
        userDao.update(user,queryWrapper);
    }

    @Test
    public void addMoney() {
        User user=new User();
        user.setModifiedTime(new Date());
        user.setModifiedUser("root");
        UpdateWrapper<User>updateWrapper=new UpdateWrapper<>();
        updateWrapper.eq("uid","15").setSql("purse=purse+"+10);
        userDao.update(user,updateWrapper);
    }

    @Test
    public void subMoney() {
    User user=new User();
    user.setModifiedTime(new Date());
    user.setModifiedUser("root");
    UpdateWrapper<User>updateWrapper=new UpdateWrapper<>();
    updateWrapper.eq("uid","15").setSql("purse=purse-"+10);
    userDao.update(user,updateWrapper);
    }

    @Test
    public void getMoney() {
    QueryWrapper<User>queryWrapper=new QueryWrapper<>();
    queryWrapper.eq("uid",15).select("purse");
    List<User>users =userDao.selectList(queryWrapper);
    users.forEach(System.out::println);
    }

    @Test
    public void addLevel() {
    UpdateWrapper<User>updateWrapper=new UpdateWrapper<>();
    updateWrapper.eq("uid",15).setSql("level=level+1");
    User user=new User();
    user.setModifiedUser("root2");
    user.setModifiedTime(new Date());
    userDao.update(user,updateWrapper);
    }

    @Test
    public void subLevel() {
    UpdateWrapper<User>userUpdateWrapper=new UpdateWrapper<>();
    userUpdateWrapper.eq("uid",15).setSql("level=level-1");
    User user=new User();
    user.setModifiedTime(new Date());
    user.setModifiedUser("root");
    userDao.update(user,userUpdateWrapper);
    }

    @Test
    public void getLevel() {
    QueryWrapper<User>queryWrapper=new QueryWrapper<>();
    queryWrapper.select("uid","level","username","user_type").eq("user_type",2);
    List<User>users=userDao.selectList(queryWrapper);
    }


    @Test
    public void getBidLevel(){
    QueryWrapper<User>queryWrapper=new QueryWrapper<>();
    queryWrapper.select("uid","username","user_type","level").eq("uid",15).eq("user_type",2);
    userDao.selectOne(queryWrapper);
    }
    /*
    @Test
    public void getLevelByBid() {

//       Integer money= userMapper.getMoney(15);
        System.out.println(userMapper.getLevelByBid(24));
    }
*/
    /*
    @Test
    public void addPoint() {
        UpdateWrapper<User>updateWrapper=new UpdateWrapper<>();
        updateWrapper.eq("uid",15).setSql("point=point+" +12);
        User user=new User();
        user.setModifiedTime(new Date());
        user.setModifiedUser("root");
        userDao.update(user,updateWrapper);
    }

    @Test
    public void subPoint() {
        UpdateWrapper<User>updateWrapper=new UpdateWrapper<>();
        updateWrapper.eq("uid",15).setSql("point=point-" +12);
        User user=new User();
        user.setModifiedTime(new Date());
        user.setModifiedUser("root");
        userDao.update(user,updateWrapper);
    }

    @Test
    public void getPoint() {
        QueryWrapper<User>queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("uid",15).select("uid","username","point");
        userDao.selectOne(queryWrapper);
    }
*/

    @Test
    public void gettest(){
        QueryWrapper<User>queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("username","zq123");
        User user=userDao.selectOne(queryWrapper);
        System.out.println(user.getIsPass());
    }

    @Test
    public void getlevelbybidtest(){
        PriorityVO priorityVO=userDao.getLevelByBid(1642449152547274753L);
        //System.out.println(priorityVO.toString());
    }

    @Test
    public void tes11(){
        String uid="''132468513648''";
        Long a= Long.valueOf(uid.substring(2,uid.length()-2));
        System.out.println(a);
    }


}
